package com.wangp.mywrite.s_netty.netty.ch2;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.*;

/**
 * @description: TODO
 * @author tooStronger
 * @date 2023/3/18
 */
@Slf4j
public class TestJdkFuture {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        // 1. 线程池
        ExecutorService service = Executors.newFixedThreadPool(2);
        // 2. 提交任务
        Future<Integer> future = service.submit(new Callable<Integer>() {
            @Override
            public Integer call() throws Exception {
                log.info("执行计算");
                Thread.sleep(500);
                return 50;
            }
        });
        // 主线程通过 future 获取结果
        log.info("等待结果");
        log.info("结果是:{}", future.get());
    }
}
